package artid.com.arttogo.activity;

import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hitomi.tilibrary.TransferImage;
import com.umeng.analytics.MobclickAgent;

import artid.com.arttogo.utils.ToastUtil;
import me.imid.swipebacklayout.lib.app.SwipeBackActivity;

/**
 * TODO<Activity基类>
 *
 * @author 熊彬
 * @data: 2015-11-30 上午9:36:53
 * @version: V1.0
 */
public class BaseActivity extends SwipeBackActivity {
    public ImageView mBack;
    public TextView mTittle;
    public RelativeLayout loading;
    public LinearLayout hint;
    public Context mContext;
    public ProgressDialog progressDialog;
    Boolean ismusicStop = false;
    public final String TAG = "BaseActivity";
    /* (non-Javadoc)
     * @see android.support.v7.app.AppCompatActivity#onCreate(android.os.Bundle)
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
//        registerReceiver(mHomeKeyEventReceiver, new IntentFilter(
//                Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        IntentFilter filter = new IntentFilter("com.BaseActivity.receiver");
        registerReceiver(broadcastReceiver, filter);
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        MobclickAgent.onPause(this);
    }

    @Override
    protected void onRestart() {
        // TODO Auto-generated method stub
        super.onRestart();
//		if (ismusicStop&&!CatalogueDetailsActivity.setMusicStop) {
//			CatalogueDetailsActivity.audioService.resumeMusic();
//		}
    }

//	private BroadcastReceiver mHomeKeyEventReceiver = new BroadcastReceiver() {
//		String SYSTEM_REASON = "reason";
//		String SYSTEM_HOME_KEY = "homekey";
//		String SYSTEM_HOME_KEY_LONG = "recentapps";
//		@Override
//		public void onReceive(Context context, Intent intent) {
//
//			String action = intent.getAction();
//			if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
//				String reason = intent.getStringExtra(SYSTEM_REASON);
//				if (TextUtils.equals(reason, SYSTEM_HOME_KEY)) {
//					//表示按了home键,程序到了后台
//					//						Toast.makeText(getApplicationContext(), "home", 1).show();
//					if (CatalogueDetailsActivity.audioService!=null) {
//						CatalogueDetailsActivity.audioService.pauseMusic();
//						ismusicStop = true;
//					}
//				}else if(TextUtils.equals(reason, SYSTEM_HOME_KEY_LONG)){
//					//表示长按home键,显示最近使用的程序列表
//				}
//			}
//		}
//	};


    ;

    //		Intent intent = new Intent();
    //        intent.setClass(this, AudioService.class);
    //		unbindService(conn);
    //        stopService(intent);
    //	}
    // 广播监听
    BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getBooleanExtra("isPushToast", false)) {
                ToastUtil.toast(BaseActivity.this, intent.getStringExtra("PushToast"));
            }
        }
    };
    protected TransferImage transferImage;

    @Override
    public void onBackPressed() {

        if (transferImage != null && transferImage.isShown()) {
            transferImage.dismiss();
        } else {
            super.onBackPressed();
        }
    }

    protected void onDestroy() {
        super.onDestroy();
//        try {
//            unregisterReceiver(mHomeKeyEventReceiver);
//        } catch (Exception e) {
//            // TODO: handle exception
//        }
        // 关闭广播
        unregisterReceiver(broadcastReceiver);
    }

}
